package models.serializer;

import play.*;
import play.db.jpa.*;

import javax.persistence.*;

import models.Comment;
import models.User;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.lang.reflect.Type;
import java.util.*;

public class UserJsonSerializer implements JsonSerializer<User> {

	public static UserJsonSerializer instance;
	
	private UserJsonSerializer() {
		
	}
	
	public static UserJsonSerializer get() {
        if (instance == null) {
            instance = new UserJsonSerializer();
        }
        return instance;
    }
	
	@Override
	public JsonElement serialize(User user, Type type, JsonSerializationContext jsonSerializationContext) {
		JsonObject obj = new JsonObject();
		obj.addProperty("email", user.email);
		obj.addProperty("name", user.name);
		obj.addProperty("realname", user.realname);
		return obj;
	}
    
}
